package com.woniu.commom;

import lombok.Data;

import java.io.Serializable;

@Data
public class CommonResult<T> implements Serializable {
    private long code;     //状态码
    private String message;   //提示消息
    private T data;    //响应数据

    public CommonResult() {

    }

    public CommonResult(long code, String message) {
        this.code = code;
        this.message = message;

    }
    public CommonResult(long code, T data) {
        this.code = code;
        this.data = data;

    }

    public CommonResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public CommonResult(T data) {

        this.data = data;
    }
    public CommonResult(String message) {

        this.message = message;
    }
    public CommonResult(String message,T data) {
        this.data = data;
        this.message = message;
    }

    /**
     * 定义响应成功的返回结果
     * 状态码：200
     *
     * @return
     */
    public static CommonResult success() {

        return new CommonResult<>(ResultUtil.SUCCESS.getCode(), ResultUtil.SUCCESS.getMessage());
    }

    public static CommonResult success(String message) {

        return new CommonResult<>(ResultUtil.SUCCESS.getCode(),message);
    }

    public static <T> CommonResult success(T data) {

        return new CommonResult<>(ResultUtil.SUCCESS.getCode(),data);
    }
    public static <T> CommonResult success(String message,T data) {

        return new CommonResult<>(ResultUtil.SUCCESS.getCode(),message,data);
    }







    /**
     * 操作失败响应结果
     * 状态码：500
     *
     * @return
     */
    public static CommonResult failed() {

        return new CommonResult<>(ResultUtil.FAILED.getCode(), ResultUtil.FAILED.getMessage());
    }
    public static CommonResult failed(String message) {

        return new CommonResult<>(ResultUtil.FAILED.getCode(),message);
    }

    /**
     * 验证参数失败
     * 状态码：400
     *
     * @return
     */
    public static CommonResult validateFialed() {
        return new CommonResult(ResultUtil.VALIDATE_PARAMETER_FIALED.getCode(), ResultUtil.VALIDATE_PARAMETER_FIALED.getMessage());
    }
    public static CommonResult validateFialed(String msg) {
        return new CommonResult(ResultUtil.VALIDATE_PARAMETER_FIALED.getCode(), msg);
    }

    /**
     * 未认证
     * 状态码：401
     *
     * @return
     */
    public static CommonResult unverified() {
        return new CommonResult(ResultUtil.UNVERIFIED.getCode(), ResultUtil.UNVERIFIED.getMessage());
    }

    /**
     * 未授权
     * 状态码：403
     *
     * @return
     */
    public static CommonResult unauthorized() {
        return new CommonResult(ResultUtil.UNAUTHORIZED.getCode(), ResultUtil.UNAUTHORIZED.getMessage());
    }

}
